package ArrayList;

import java.util.*;

public class UnsafeArrayListDemo {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();

        Runnable task = () -> {
            for (int i = 0; i < 1000; i++) {
                list.add(i); // 多线程同时写
            }
        };

        Thread t1 = new Thread(task);
        Thread t2 = new Thread(task);
        t1.start();
        t2.start();

        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) { }

        System.out.println("最终大小: " + list.size());  // ⚠️ 可能不是 2000！
    }
}
